<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class CSV::Table - csv: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-CSV::Table-label-CSV-3A-3ATable">CSV::Table</a>
    <li><a href="#class-CSV::Table-label-Instance+Methods">Instance Methods</a>
    <li><a href="#class-CSV::Table-label-Creating+a+CSV-3A-3ATable+Instance">Creating a CSV::Table Instance</a>
    <li><a href="#class-CSV::Table-label-Headers">Headers</a>
    <li><a href="#class-CSV::Table-label-Access+Modes">Access Modes</a>
    <li><a href="#class-CSV::Table-label-Row+Mode">Row Mode</a>
    <li><a href="#class-CSV::Table-label-Column+Mode">Column Mode</a>
    <li><a href="#class-CSV::Table-label-Mixed+Mode">Mixed Mode</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="../Object.html">Object</a>
</div>

        
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><span class="include">Enumerable</span>
  </ul>
</div>

        
<div id="extends-section" class="nav-section">
  <h3>Extended With Modules</h3>

  <ul class="link-list">
    <li><span class="extend">Forwardable</span>
  </ul>
</div>

        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-3C-3C">#&lt;&lt;</a>
    <li ><a href="#method-i-3D-3D">#==</a>
    <li ><a href="#method-i-5B-5D">#[]</a>
    <li ><a href="#method-i-5B-5D-3D">#[]=</a>
    <li ><a href="#method-i-by_col">#by_col</a>
    <li ><a href="#method-i-by_col-21">#by_col!</a>
    <li ><a href="#method-i-by_col_or_row">#by_col_or_row</a>
    <li ><a href="#method-i-by_col_or_row-21">#by_col_or_row!</a>
    <li ><a href="#method-i-by_row">#by_row</a>
    <li ><a href="#method-i-by_row-21">#by_row!</a>
    <li ><a href="#method-i-delete">#delete</a>
    <li ><a href="#method-i-delete_if">#delete_if</a>
    <li ><a href="#method-i-dig">#dig</a>
    <li ><a href="#method-i-each">#each</a>
    <li ><a href="#method-i-headers">#headers</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-push">#push</a>
    <li ><a href="#method-i-to_a">#to_a</a>
    <li ><a href="#method-i-to_csv">#to_csv</a>
    <li ><a href="#method-i-to_s">#to_s</a>
    <li ><a href="#method-i-values_at">#values_at</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-CSV::Table">
    <h1 id="class-CSV::Table" class="class">
      class CSV::Table
    </h1>

    <section class="description">
    
<h1 id="class-CSV::Table-label-CSV-3A-3ATable">CSV::Table<span><a href="#class-CSV::Table-label-CSV-3A-3ATable">&para;</a> <a href="#top">&uarr;</a></span></h1>

<p>A CSV::Table instance represents CSV data. (see <a href="../CSV.html">class CSV</a>).</p>

<p>The instance may have:</p>
<ul><li>
<p>Rows: each is a Table::Row object.</p>
</li><li>
<p>Headers: names for the columns.</p>
</li></ul>

<h3 id="class-CSV::Table-label-Instance+Methods">Instance Methods<span><a href="#class-CSV::Table-label-Instance+Methods">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>CSV::Table has three groups of instance methods:</p>
<ul><li>
<p>Its own internally defined instance methods.</p>
</li><li>
<p>Methods included by module Enumerable.</p>
</li><li>
<p>Methods delegated to class Array.:</p>
<ul><li>
<p>Array#empty?</p>
</li><li>
<p>Array#length</p>
</li><li>
<p>Array#size</p>
</li></ul>
</li></ul>

<h2 id="class-CSV::Table-label-Creating+a+CSV-3A-3ATable+Instance">Creating a CSV::Table Instance<span><a href="#class-CSV::Table-label-Creating+a+CSV-3A-3ATable+Instance">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Commonly, a new CSV::Table instance is created by parsing CSV source using headers:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">class</span> <span class="ruby-comment"># =&gt; CSV::Table</span>
</pre>

<p>You can also create an instance directly. See <a href="Table.html#method-c-new"><code>::new</code></a>.</p>

<h2 id="class-CSV::Table-label-Headers">Headers<span><a href="#class-CSV::Table-label-Headers">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>If a table has headers, the headers serve as labels for the columns of data. Each header serves as the label for its column.</p>

<p>The headers for a CSV::Table object are stored as an Array of Strings.</p>

<p>Commonly, headers are defined in the first row of CSV source:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">headers</span> <span class="ruby-comment"># =&gt; [&quot;Name&quot;, &quot;Value&quot;]</span>
</pre>

<p>If no headers are defined, the Array is empty:</p>

<pre class="ruby"><span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Table</span>.<span class="ruby-identifier">new</span>([])
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">headers</span> <span class="ruby-comment"># =&gt; []</span>
</pre>

<h2 id="class-CSV::Table-label-Access+Modes">Access Modes<span><a href="#class-CSV::Table-label-Access+Modes">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>CSV::Table provides three modes for accessing table data:</p>
<ul><li>
<p>Row mode.</p>
</li><li>
<p>Column mode.</p>
</li><li>
<p>Mixed mode (the default for a new table).</p>
</li></ul>

<p>The access mode for aCSV::Table instance affects the behavior of some of its instance methods:</p>
<ul><li>
<p><a href="Table.html#method-i-5B-5D"><code>[]</code></a></p>
</li><li>
<p><a href="Table.html#method-i-5B-5D-3D"><code>[]=</code></a></p>
</li><li>
<p><a href="Table.html#method-i-delete"><code>delete</code></a></p>
</li><li>
<p><a href="Table.html#method-i-delete_if"><code>delete_if</code></a></p>
</li><li>
<p><a href="Table.html#method-i-each"><code>each</code></a></p>
</li><li>
<p><a href="Table.html#method-i-values_at"><code>values_at</code></a></p>
</li></ul>

<h3 id="class-CSV::Table-label-Row+Mode">Row Mode<span><a href="#class-CSV::Table-label-Row+Mode">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Set a table to row mode with method <a href="Table.html#method-i-by_row-21"><code>by_row!</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_row!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:row row_count:4&gt;</span>
</pre>

<p>Specify a single row by an Integer index:</p>

<pre class="ruby"><span class="ruby-comment"># Get a row.</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; #&lt;CSV::Row &quot;Name&quot;:&quot;bar&quot; &quot;Value&quot;:&quot;1&quot;&gt;</span>
<span class="ruby-comment"># Set a row, then get it.</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] = <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&#39;Name&#39;</span>, <span class="ruby-string">&#39;Value&#39;</span>], [<span class="ruby-string">&#39;bam&#39;</span>, <span class="ruby-value">3</span>])
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; #&lt;CSV::Row &quot;Name&quot;:&quot;bam&quot; &quot;Value&quot;:3&gt;</span>
</pre>

<p>Specify a sequence of rows by a Range:</p>

<pre class="ruby"><span class="ruby-comment"># Get rows.</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">2</span>] <span class="ruby-comment"># =&gt; [#&lt;CSV::Row &quot;Name&quot;:&quot;bam&quot; &quot;Value&quot;:3&gt;, #&lt;CSV::Row &quot;Name&quot;:&quot;baz&quot; &quot;Value&quot;:&quot;2&quot;&gt;]</span>
<span class="ruby-comment"># Set rows, then get them.</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">2</span>] = [
  <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&#39;Name&#39;</span>, <span class="ruby-string">&#39;Value&#39;</span>], [<span class="ruby-string">&#39;bat&#39;</span>, <span class="ruby-value">4</span>]),
  <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&#39;Name&#39;</span>, <span class="ruby-string">&#39;Value&#39;</span>], [<span class="ruby-string">&#39;bad&#39;</span>, <span class="ruby-value">5</span>]),
]
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">2</span>] <span class="ruby-comment"># =&gt; [[&quot;Name&quot;, #&lt;CSV::Row &quot;Name&quot;:&quot;bat&quot; &quot;Value&quot;:4&gt;], [&quot;Value&quot;, #&lt;CSV::Row &quot;Name&quot;:&quot;bad&quot; &quot;Value&quot;:5&gt;]]</span>
</pre>

<h3 id="class-CSV::Table-label-Column+Mode">Column Mode<span><a href="#class-CSV::Table-label-Column+Mode">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Set a table to column mode with method <a href="Table.html#method-i-by_col-21"><code>by_col!</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col row_count:4&gt;</span>
</pre>

<p>Specify a column by an Integer index:</p>

<pre class="ruby"><span class="ruby-comment"># Get a column.</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">0</span>]
<span class="ruby-comment"># Set a column, then get it.</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">0</span>] = [<span class="ruby-string">&#39;FOO&#39;</span>, <span class="ruby-string">&#39;BAR&#39;</span>, <span class="ruby-string">&#39;BAZ&#39;</span>]
<span class="ruby-identifier">table</span>[<span class="ruby-value">0</span>] <span class="ruby-comment"># =&gt; [&quot;FOO&quot;, &quot;BAR&quot;, &quot;BAZ&quot;]</span>
</pre>

<p>Specify a column by its String header:</p>

<pre class="ruby"><span class="ruby-comment"># Get a column.</span>
<span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Name&#39;</span>] <span class="ruby-comment"># =&gt; [&quot;FOO&quot;, &quot;BAR&quot;, &quot;BAZ&quot;]</span>
<span class="ruby-comment"># Set a column, then get it.</span>
<span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Name&#39;</span>] = [<span class="ruby-string">&#39;Foo&#39;</span>, <span class="ruby-string">&#39;Bar&#39;</span>, <span class="ruby-string">&#39;Baz&#39;</span>]
<span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Name&#39;</span>] <span class="ruby-comment"># =&gt; [&quot;Foo&quot;, &quot;Bar&quot;, &quot;Baz&quot;]</span>
</pre>

<h3 id="class-CSV::Table-label-Mixed+Mode">Mixed Mode<span><a href="#class-CSV::Table-label-Mixed+Mode">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>In mixed mode, you can refer to either rows or columns:</p>
<ul><li>
<p>An Integer index refers to a row.</p>
</li><li>
<p>A Range index refers to multiple rows.</p>
</li><li>
<p>A String index refers to a column.</p>
</li></ul>

<p>Set a table to mixed mode with method <a href="Table.html#method-i-by_col_or_row-21"><code>by_col_or_row!</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col_or_row!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col_or_row row_count:4&gt;</span>
</pre>

<p>Specify a single row by an Integer index:</p>

<pre class="ruby"><span class="ruby-comment"># Get a row.</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; #&lt;CSV::Row &quot;Name&quot;:&quot;bar&quot; &quot;Value&quot;:&quot;1&quot;&gt;</span>
<span class="ruby-comment"># Set a row, then get it.</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] = <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&#39;Name&#39;</span>, <span class="ruby-string">&#39;Value&#39;</span>], [<span class="ruby-string">&#39;bam&#39;</span>, <span class="ruby-value">3</span>])
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; #&lt;CSV::Row &quot;Name&quot;:&quot;bam&quot; &quot;Value&quot;:3&gt;</span>
</pre>

<p>Specify a sequence of rows by a Range:</p>

<pre class="ruby"><span class="ruby-comment"># Get rows.</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">2</span>] <span class="ruby-comment"># =&gt; [#&lt;CSV::Row &quot;Name&quot;:&quot;bam&quot; &quot;Value&quot;:3&gt;, #&lt;CSV::Row &quot;Name&quot;:&quot;baz&quot; &quot;Value&quot;:&quot;2&quot;&gt;]</span>
<span class="ruby-comment"># Set rows, then get them.</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] = <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&#39;Name&#39;</span>, <span class="ruby-string">&#39;Value&#39;</span>], [<span class="ruby-string">&#39;bat&#39;</span>, <span class="ruby-value">4</span>])
<span class="ruby-identifier">table</span>[<span class="ruby-value">2</span>] = <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&#39;Name&#39;</span>, <span class="ruby-string">&#39;Value&#39;</span>], [<span class="ruby-string">&#39;bad&#39;</span>, <span class="ruby-value">5</span>])
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">2</span>] <span class="ruby-comment"># =&gt; [[&quot;Name&quot;, #&lt;CSV::Row &quot;Name&quot;:&quot;bat&quot; &quot;Value&quot;:4&gt;], [&quot;Value&quot;, #&lt;CSV::Row &quot;Name&quot;:&quot;bad&quot; &quot;Value&quot;:5&gt;]]</span>
</pre>

<p>Specify a column by its String header:</p>

<pre class="ruby"><span class="ruby-comment"># Get a column.</span>
<span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Name&#39;</span>] <span class="ruby-comment"># =&gt; [&quot;foo&quot;, &quot;bat&quot;, &quot;bad&quot;]</span>
<span class="ruby-comment"># Set a column, then get it.</span>
<span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Name&#39;</span>] = [<span class="ruby-string">&#39;Foo&#39;</span>, <span class="ruby-string">&#39;Bar&#39;</span>, <span class="ruby-string">&#39;Baz&#39;</span>]
<span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Name&#39;</span>] <span class="ruby-comment"># =&gt; [&quot;Foo&quot;, &quot;Bar&quot;, &quot;Baz&quot;]</span>
</pre>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">



        <section class="attribute-method-details" class="method-section">
        <header>
        <h3>Attributes</h3>
        </header>

          <div id="attribute-i-mode" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">mode</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>The current access mode for indexing and iteration.</p>
              </div>
            </div>
          <div id="attribute-i-table" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">table</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Internal data format used to compare equality.</p>
              </div>
            </div>
            </section>


                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          CSV::Table.new(array_of_rows, headers = nil) &rarr; csv_table
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new CSV::Table object.</p>
<ul><li>
<p>Argument <code>array_of_rows</code> must be an Array of <a href="Row.html"><code>CSV::Row</code></a> objects.</p>
</li><li>
<p>Argument <code>headers</code>, if given, may be an Array of Strings.</p>
</li></ul>
<hr>

<p>Create an empty CSV::Table object:</p>

<pre class="ruby"><span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Table</span>.<span class="ruby-identifier">new</span>([])
<span class="ruby-identifier">table</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col_or_row row_count:1&gt;</span>
</pre>

<p>Create a non-empty CSV::Table object:</p>

<pre class="ruby"><span class="ruby-identifier">rows</span> = [
  <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([], []),
  <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([], []),
  <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([], []),
]
<span class="ruby-identifier">table</span>  = <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Table</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">rows</span>)
<span class="ruby-identifier">table</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col_or_row row_count:4&gt;</span>
</pre>
<hr>

<p>If argument <code>headers</code> is an Array of Strings, those Strings become the table’s headers:</p>

<pre class="ruby"><span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Table</span>.<span class="ruby-identifier">new</span>([], <span class="ruby-value">headers:</span> [<span class="ruby-string">&#39;Name&#39;</span>, <span class="ruby-string">&#39;Age&#39;</span>])
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">headers</span> <span class="ruby-comment"># =&gt; [&quot;Name&quot;, &quot;Age&quot;]</span>
</pre>

<p>If argument <code>headers</code> is not given and the table has rows, the headers are taken from the first row:</p>

<pre class="ruby"><span class="ruby-identifier">rows</span> = [
  <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&#39;Foo&#39;</span>, <span class="ruby-string">&#39;Bar&#39;</span>], []),
  <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&#39;foo&#39;</span>, <span class="ruby-string">&#39;bar&#39;</span>], []),
  <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&#39;FOO&#39;</span>, <span class="ruby-string">&#39;BAR&#39;</span>], []),
]
<span class="ruby-identifier">table</span>  = <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Table</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">rows</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">headers</span> <span class="ruby-comment"># =&gt; [&quot;Foo&quot;, &quot;Bar&quot;]</span>
</pre>

<p>If argument <code>headers</code> is not given and the table is empty (has no rows), the headers are also empty:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>  = <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Table</span>.<span class="ruby-identifier">new</span>([])
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">headers</span> <span class="ruby-comment"># =&gt; []</span>
</pre>
<hr>

<p>Raises an exception if argument <code>array_of_rows</code> is not an Array object:</p>

<pre class="ruby"><span class="ruby-comment"># Raises NoMethodError (undefined method `first&#39; for :foo:Symbol):</span>
<span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Table</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:foo</span>)
</pre>

<p>Raises an exception if an element of <code>array_of_rows</code> is not a CSV::Table object:</p>

<pre class="ruby"><span class="ruby-comment"># Raises NoMethodError (undefined method `headers&#39; for :foo:Symbol):</span>
<span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Table</span>.<span class="ruby-identifier">new</span>([<span class="ruby-value">:foo</span>])
</pre>

                              <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 199</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">array_of_rows</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">nil</span>)
  <span class="ruby-ivar">@table</span> = <span class="ruby-identifier">array_of_rows</span>
  <span class="ruby-ivar">@headers</span> = <span class="ruby-identifier">headers</span>
  <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@headers</span>
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">empty?</span>
      <span class="ruby-ivar">@headers</span> = []
    <span class="ruby-keyword">else</span>
      <span class="ruby-ivar">@headers</span> = <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">headers</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-ivar">@mode</span>  = <span class="ruby-value">:col_or_row</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-3C-3C" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          table &lt;&lt; row_or_array &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>If <code>row_or_array</code> is a CSV::Row object, it is appended to the table:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">table</span>.<span class="ruby-identifier">headers</span>, [<span class="ruby-string">&#39;bat&#39;</span>, <span class="ruby-value">3</span>])
<span class="ruby-identifier">table</span>[<span class="ruby-value">3</span>] <span class="ruby-comment"># =&gt; #&lt;CSV::Row &quot;Name&quot;:&quot;bat&quot; &quot;Value&quot;:3&gt;</span>
</pre>

<p>If <code>row_or_array</code> is an Array, it is used to create a new CSV::Row object which is then appended to the table:</p>

<pre class="ruby"><span class="ruby-identifier">table</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-string">&#39;bam&#39;</span>, <span class="ruby-value">4</span>]
<span class="ruby-identifier">table</span>[<span class="ruby-value">4</span>] <span class="ruby-comment"># =&gt; #&lt;CSV::Row &quot;Name&quot;:&quot;bam&quot; &quot;Value&quot;:4&gt;</span>
</pre>

                              <div class="method-source-code" id="3C-3C-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 762</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">&lt;&lt;</span>(<span class="ruby-identifier">row_or_array</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">row_or_array</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Array</span>  <span class="ruby-comment"># append Array</span>
    <span class="ruby-ivar">@table</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">headers</span>, <span class="ruby-identifier">row_or_array</span>)
  <span class="ruby-keyword">else</span>                         <span class="ruby-comment"># append Row</span>
    <span class="ruby-ivar">@table</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">row_or_array</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">self</span> <span class="ruby-comment"># for chaining</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-3D-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          table == other_table &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if all each row of <code>self</code> <code>==</code> the corresponding row of <code>other_table</code>, otherwise, <code>false</code>.</p>

<p>The access mode does no affect the result.</p>

<p>Equal tables:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">other_table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other_table</span> <span class="ruby-comment"># =&gt; true</span>
</pre>

<p>Different row count:</p>

<pre class="ruby"><span class="ruby-identifier">other_table</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">2</span>)
<span class="ruby-identifier">table</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other_table</span> <span class="ruby-comment"># =&gt; false</span>
</pre>

<p>Different last row:</p>

<pre class="ruby"><span class="ruby-identifier">other_table</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-string">&#39;bat&#39;</span>, <span class="ruby-value">3</span>]
<span class="ruby-identifier">table</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other_table</span> <span class="ruby-comment"># =&gt; false</span>
</pre>

                              <div class="method-source-code" id="3D-3D-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 965</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">==</span>(<span class="ruby-identifier">other</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-ivar">@table</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">table</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Table</span>
  <span class="ruby-ivar">@table</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-5B-5D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          table[n] &rarr; row or column_data
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          table[range] &rarr; array_of_rows or array_of_column_data
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          table[header] &rarr; array_of_column_data
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns data from the table;  does not modify the table.</p>
<hr>
<dl class="rdoc-list note-list"><dt>Fetch a Row by Its Integer Index
<dd></dd></dl>
<ul><li>
<p>Form: <code>table[n]</code>, <code>n</code> an integer.</p>
</li><li>
<p>Access mode: <code>:row</code> or <code>:col_or_row</code>.</p>
</li><li>
<p>Return value: <em>nth</em> row of the table, if that row exists; otherwise <code>nil</code>.</p>
</li></ul>

<p>Returns the <em>nth</em> row of the table if that row exists:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_row!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:row row_count:4&gt;</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; #&lt;CSV::Row &quot;Name&quot;:&quot;bar&quot; &quot;Value&quot;:&quot;1&quot;&gt;</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col_or_row!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col_or_row row_count:4&gt;</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; #&lt;CSV::Row &quot;Name&quot;:&quot;bar&quot; &quot;Value&quot;:&quot;1&quot;&gt;</span>
</pre>

<p>Counts backward from the last row if <code>n</code> is negative:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-value">-1</span>] <span class="ruby-comment"># =&gt; #&lt;CSV::Row &quot;Name&quot;:&quot;baz&quot; &quot;Value&quot;:&quot;2&quot;&gt;</span>
</pre>

<p>Returns <code>nil</code> if <code>n</code> is too large or too small:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-value">4</span>] <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">-4</span>] <span class="ruby-comment"># =&gt; nil</span>
</pre>

<p>Raises an exception if the access mode is <code>:row</code> and <code>n</code> is not an Integer:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_row!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:row row_count:4&gt;</span>
<span class="ruby-comment"># Raises TypeError (no implicit conversion of String into Integer):</span>
<span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Name&#39;</span>]
</pre>
<hr>
<dl class="rdoc-list note-list"><dt>Fetch a Column by Its Integer Index
<dd></dd></dl>
<ul><li>
<p>Form: <code>table[n]</code>, <code>n</code> an Integer.</p>
</li><li>
<p>Access mode: <code>:col</code>.</p>
</li><li>
<p>Return value: <em>nth</em> column of the table, if that column exists; otherwise an Array of <code>nil</code> fields of length <code>self.size</code>.</p>
</li></ul>

<p>Returns the <em>nth</em> column of the table if that column exists:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col row_count:4&gt;</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; [&quot;0&quot;, &quot;1&quot;, &quot;2&quot;]</span>
</pre>

<p>Counts backward from the last column if <code>n</code> is negative:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-value">-2</span>] <span class="ruby-comment"># =&gt; [&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;]</span>
</pre>

<p>Returns an Array of <code>nil</code> fields if <code>n</code> is too large or too small:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-value">4</span>] <span class="ruby-comment"># =&gt; [nil, nil, nil]</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">-4</span>] <span class="ruby-comment"># =&gt; [nil, nil, nil]</span>
</pre>
<hr>
<dl class="rdoc-list note-list"><dt>Fetch Rows by Range
<dd></dd></dl>
<ul><li>
<p>Form: <code>table[range]</code>, <code>range</code> a Range object.</p>
</li><li>
<p>Access mode: <code>:row</code> or <code>:col_or_row</code>.</p>
</li><li>
<p>Return value: rows from the table, beginning at row <code>range.start</code>, if those rows exists.</p>
</li></ul>

<p>Returns rows from the table, beginning at row <code>range.first</code>, if those rows exist:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_row!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:row row_count:4&gt;</span>
<span class="ruby-identifier">rows</span> = <span class="ruby-identifier">table</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">2</span>] <span class="ruby-comment"># =&gt; #&lt;CSV::Row &quot;Name&quot;:&quot;bar&quot; &quot;Value&quot;:&quot;1&quot;&gt;</span>
<span class="ruby-identifier">rows</span> <span class="ruby-comment"># =&gt; [#&lt;CSV::Row &quot;Name&quot;:&quot;bar&quot; &quot;Value&quot;:&quot;1&quot;&gt;, #&lt;CSV::Row &quot;Name&quot;:&quot;baz&quot; &quot;Value&quot;:&quot;2&quot;&gt;]</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col_or_row!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col_or_row row_count:4&gt;</span>
<span class="ruby-identifier">rows</span> = <span class="ruby-identifier">table</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">2</span>] <span class="ruby-comment"># =&gt; #&lt;CSV::Row &quot;Name&quot;:&quot;bar&quot; &quot;Value&quot;:&quot;1&quot;&gt;</span>
<span class="ruby-identifier">rows</span> <span class="ruby-comment"># =&gt; [#&lt;CSV::Row &quot;Name&quot;:&quot;bar&quot; &quot;Value&quot;:&quot;1&quot;&gt;, #&lt;CSV::Row &quot;Name&quot;:&quot;baz&quot; &quot;Value&quot;:&quot;2&quot;&gt;]</span>
</pre>

<p>If there are too few rows, returns all from <code>range.start</code> to the end:</p>

<pre class="ruby"><span class="ruby-identifier">rows</span> = <span class="ruby-identifier">table</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">50</span>] <span class="ruby-comment"># =&gt; #&lt;CSV::Row &quot;Name&quot;:&quot;bar&quot; &quot;Value&quot;:&quot;1&quot;&gt;</span>
<span class="ruby-identifier">rows</span> <span class="ruby-comment"># =&gt; [#&lt;CSV::Row &quot;Name&quot;:&quot;bar&quot; &quot;Value&quot;:&quot;1&quot;&gt;, #&lt;CSV::Row &quot;Name&quot;:&quot;baz&quot; &quot;Value&quot;:&quot;2&quot;&gt;]</span>
</pre>

<p>Special case: if <code>range.start == table.size</code>, returns an empty Array:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-identifier">table</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">..</span><span class="ruby-value">50</span>] <span class="ruby-comment"># =&gt; []</span>
</pre>

<p>If <code>range.end</code> is negative, calculates the ending index from the end:</p>

<pre class="ruby"><span class="ruby-identifier">rows</span> = <span class="ruby-identifier">table</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]
<span class="ruby-identifier">rows</span> <span class="ruby-comment"># =&gt; [#&lt;CSV::Row &quot;Name&quot;:&quot;foo&quot; &quot;Value&quot;:&quot;0&quot;&gt;, #&lt;CSV::Row &quot;Name&quot;:&quot;bar&quot; &quot;Value&quot;:&quot;1&quot;&gt;, #&lt;CSV::Row &quot;Name&quot;:&quot;baz&quot; &quot;Value&quot;:&quot;2&quot;&gt;]</span>
</pre>

<p>If <code>range.start</code> is negative, calculates the starting index from the end:</p>

<pre class="ruby"><span class="ruby-identifier">rows</span> = <span class="ruby-identifier">table</span>[<span class="ruby-value">-1</span><span class="ruby-operator">..</span><span class="ruby-value">2</span>]
<span class="ruby-identifier">rows</span> <span class="ruby-comment"># =&gt; [#&lt;CSV::Row &quot;Name&quot;:&quot;baz&quot; &quot;Value&quot;:&quot;2&quot;&gt;]</span>
</pre>

<p>If <code>range.start</code> is larger than <code>table.size</code>, returns <code>nil</code>:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-value">4</span><span class="ruby-operator">..</span><span class="ruby-value">4</span>] <span class="ruby-comment"># =&gt; nil</span>
</pre>
<hr>
<dl class="rdoc-list note-list"><dt>Fetch Columns by Range
<dd></dd></dl>
<ul><li>
<p>Form: <code>table[range]</code>, <code>range</code> a Range object.</p>
</li><li>
<p>Access mode: <code>:col</code>.</p>
</li><li>
<p>Return value: column data from the table, beginning at column <code>range.start</code>, if those columns exist.</p>
</li></ul>

<p>Returns column values from the table, if the column exists; the values are arranged by row:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col!</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; [[&quot;foo&quot;, &quot;0&quot;], [&quot;bar&quot;, &quot;1&quot;], [&quot;baz&quot;, &quot;2&quot;]]</span>
</pre>

<p>Special case: if <code>range.start == headers.size</code>, returns an Array (size: <code>table.size</code>) of empty Arrays:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-identifier">table</span>.<span class="ruby-identifier">headers</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">..</span><span class="ruby-value">50</span>] <span class="ruby-comment"># =&gt; [[], [], []]</span>
</pre>

<p>If <code>range.end</code> is negative, calculates the ending index from the end:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>] <span class="ruby-comment"># =&gt; [[&quot;foo&quot;, &quot;0&quot;], [&quot;bar&quot;, &quot;1&quot;], [&quot;baz&quot;, &quot;2&quot;]]</span>
</pre>

<p>If <code>range.start</code> is negative, calculates the starting index from the end:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-value">-2</span><span class="ruby-operator">..</span><span class="ruby-value">2</span>] <span class="ruby-comment"># =&gt; [[&quot;foo&quot;, &quot;0&quot;], [&quot;bar&quot;, &quot;1&quot;], [&quot;baz&quot;, &quot;2&quot;]]</span>
</pre>

<p>If <code>range.start</code> is larger than <code>table.size</code>, returns an Array of <code>nil</code> values:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-value">4</span><span class="ruby-operator">..</span><span class="ruby-value">4</span>] <span class="ruby-comment"># =&gt; [nil, nil, nil]</span>
</pre>
<hr>
<dl class="rdoc-list note-list"><dt>Fetch a Column by Its String Header
<dd></dd></dl>
<ul><li>
<p>Form: <code>table[header]</code>, <code>header</code> a String header.</p>
</li><li>
<p>Access mode: <code>:col</code> or <code>:col_or_row</code></p>
</li><li>
<p>Return value: column data from the table, if that <code>header</code> exists.</p>
</li></ul>

<p>Returns column values from the table, if the column exists:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col row_count:4&gt;</span>
<span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Name&#39;</span>] <span class="ruby-comment"># =&gt; [&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;]</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col_or_row!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col_or_row row_count:4&gt;</span>
<span class="ruby-identifier">col</span> = <span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Name&#39;</span>]
<span class="ruby-identifier">col</span> <span class="ruby-comment"># =&gt; [&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;]</span>
</pre>

<p>Modifying the returned column values does not modify the table:</p>

<pre class="ruby"><span class="ruby-identifier">col</span>[<span class="ruby-value">0</span>] = <span class="ruby-string">&#39;bat&#39;</span>
<span class="ruby-identifier">col</span> <span class="ruby-comment"># =&gt; [&quot;bat&quot;, &quot;bar&quot;, &quot;baz&quot;]</span>
<span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Name&#39;</span>] <span class="ruby-comment"># =&gt; [&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;]</span>
</pre>

<p>Returns an Array of <code>nil</code> values if there is no such column:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Nosuch&#39;</span>] <span class="ruby-comment"># =&gt; [nil, nil, nil]</span>
</pre>

                              <div class="method-source-code" id="5B-5D-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 514</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">[]</span>(<span class="ruby-identifier">index_or_header</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@mode</span> <span class="ruby-operator">==</span> <span class="ruby-value">:row</span> <span class="ruby-keyword">or</span>  <span class="ruby-comment"># by index</span>
     (<span class="ruby-ivar">@mode</span> <span class="ruby-operator">==</span> <span class="ruby-value">:col_or_row</span> <span class="ruby-keyword">and</span> (<span class="ruby-identifier">index_or_header</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Integer</span>) <span class="ruby-keyword">or</span> <span class="ruby-identifier">index_or_header</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Range</span>)))
    <span class="ruby-ivar">@table</span>[<span class="ruby-identifier">index_or_header</span>]
  <span class="ruby-keyword">else</span>                 <span class="ruby-comment"># by header</span>
    <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span> <span class="ruby-identifier">row</span>[<span class="ruby-identifier">index_or_header</span>] }
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-5B-5D-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          table[n] = row &rarr; row
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          table[n] = field_or_array_of_fields &rarr; field_or_array_of_fields
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          table[header] = field_or_array_of_fields &rarr; field_or_array_of_fields
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Puts data onto the table.</p>
<hr>
<dl class="rdoc-list note-list"><dt>Set a Row by Its Integer Index
<dd></dd></dl>
<ul><li>
<p>Form: <code>table[n] = row</code>, <code>n</code> an Integer, <code>row</code> a CSV::Row instance or an Array of fields.</p>
</li><li>
<p>Access mode: <code>:row</code> or <code>:col_or_row</code>.</p>
</li><li>
<p>Return value: <code>row</code>.</p>
</li></ul>

<p>If the row exists, it is replaced:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">new_row</span> = <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&#39;Name&#39;</span>, <span class="ruby-string">&#39;Value&#39;</span>], [<span class="ruby-string">&#39;bat&#39;</span>, <span class="ruby-value">3</span>])
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_row!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:row row_count:4&gt;</span>
<span class="ruby-identifier">return_value</span> = <span class="ruby-identifier">table</span>[<span class="ruby-value">0</span>] = <span class="ruby-identifier">new_row</span>
<span class="ruby-identifier">return_value</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">new_row</span>) <span class="ruby-comment"># =&gt; true # Returned the row</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">to_h</span> <span class="ruby-comment"># =&gt; {&quot;Name&quot;=&gt;&quot;bat&quot;, &quot;Value&quot;=&gt;3}</span>
</pre>

<p>With access mode <code>:col_or_row</code>:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col_or_row!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col_or_row row_count:4&gt;</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">0</span>] = <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&#39;Name&#39;</span>, <span class="ruby-string">&#39;Value&#39;</span>], [<span class="ruby-string">&#39;bam&#39;</span>, <span class="ruby-value">4</span>])
<span class="ruby-identifier">table</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">to_h</span> <span class="ruby-comment"># =&gt; {&quot;Name&quot;=&gt;&quot;bam&quot;, &quot;Value&quot;=&gt;4}</span>
</pre>

<p>With an Array instead of a CSV::Row, inherits headers from the table:</p>

<pre class="ruby"><span class="ruby-identifier">array</span> = [<span class="ruby-string">&#39;bad&#39;</span>, <span class="ruby-value">5</span>]
<span class="ruby-identifier">return_value</span> = <span class="ruby-identifier">table</span>[<span class="ruby-value">0</span>] = <span class="ruby-identifier">array</span>
<span class="ruby-identifier">return_value</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">array</span>) <span class="ruby-comment"># =&gt; true # Returned the array</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">to_h</span> <span class="ruby-comment"># =&gt; {&quot;Name&quot;=&gt;&quot;bad&quot;, &quot;Value&quot;=&gt;5}</span>
</pre>

<p>If the row does not exist, extends the table by adding rows: assigns rows with <code>nil</code> as needed:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment"># =&gt; 3</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">5</span>] = [<span class="ruby-string">&#39;bag&#39;</span>, <span class="ruby-value">6</span>]
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment"># =&gt; 6</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">3</span>] <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">4</span>]<span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">5</span>].<span class="ruby-identifier">to_h</span> <span class="ruby-comment"># =&gt; {&quot;Name&quot;=&gt;&quot;bag&quot;, &quot;Value&quot;=&gt;6}</span>
</pre>

<p>Note that the <code>nil</code> rows are actually <code>nil</code>, not a row of <code>nil</code> fields.</p>
<hr>
<dl class="rdoc-list note-list"><dt>Set a Column by Its Integer Index
<dd></dd></dl>
<ul><li>
<p>Form: <code>table[n] = array_of_fields</code>, <code>n</code> an Integer, <code>array_of_fields</code> an Array of String fields.</p>
</li><li>
<p>Access mode: <code>:col</code>.</p>
</li><li>
<p>Return value: <code>array_of_fields</code>.</p>
</li></ul>

<p>If the column exists, it is replaced:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">new_col</span> = [<span class="ruby-value">3</span>, <span class="ruby-value">4</span>, <span class="ruby-value">5</span>]
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col row_count:4&gt;</span>
<span class="ruby-identifier">return_value</span> = <span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] = <span class="ruby-identifier">new_col</span>
<span class="ruby-identifier">return_value</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">new_col</span>) <span class="ruby-comment"># =&gt; true # Returned the column</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; [3, 4, 5]</span>
<span class="ruby-comment"># The rows, as revised:</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_row!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:row row_count:4&gt;</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">to_h</span> <span class="ruby-comment"># =&gt; {&quot;Name&quot;=&gt;&quot;foo&quot;, &quot;Value&quot;=&gt;3}</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_h</span> <span class="ruby-comment"># =&gt; {&quot;Name&quot;=&gt;&quot;bar&quot;, &quot;Value&quot;=&gt;4}</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">2</span>].<span class="ruby-identifier">to_h</span> <span class="ruby-comment"># =&gt; {&quot;Name&quot;=&gt;&quot;baz&quot;, &quot;Value&quot;=&gt;5}</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col row_count:4&gt;</span>
</pre>

<p>If there are too few values, fills with <code>nil</code> values:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] = [<span class="ruby-value">0</span>]
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; [0, nil, nil]</span>
</pre>

<p>If there are too many values, ignores the extra values:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] = [<span class="ruby-value">0</span>, <span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>, <span class="ruby-value">4</span>]
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; [0, 1, 2]</span>
</pre>

<p>If a single value is given, replaces all fields in the column with that value:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] = <span class="ruby-string">&#39;bat&#39;</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; [&quot;bat&quot;, &quot;bat&quot;, &quot;bat&quot;]</span>
</pre>
<hr>
<dl class="rdoc-list note-list"><dt>Set a Column by Its String Header
<dd></dd></dl>
<ul><li>
<p>Form: <code>table[header] = field_or_array_of_fields</code>, <code>header</code> a String header, <code>field_or_array_of_fields</code> a field value or an Array of String fields.</p>
</li><li>
<p>Access mode: <code>:col</code> or <code>:col_or_row</code>.</p>
</li><li>
<p>Return value: <code>field_or_array_of_fields</code>.</p>
</li></ul>

<p>If the column exists, it is replaced:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">new_col</span> = [<span class="ruby-value">3</span>, <span class="ruby-value">4</span>, <span class="ruby-value">5</span>]
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col row_count:4&gt;</span>
<span class="ruby-identifier">return_value</span> = <span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Value&#39;</span>] = <span class="ruby-identifier">new_col</span>
<span class="ruby-identifier">return_value</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">new_col</span>) <span class="ruby-comment"># =&gt; true # Returned the column</span>
<span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Value&#39;</span>] <span class="ruby-comment"># =&gt; [3, 4, 5]</span>
<span class="ruby-comment"># The rows, as revised:</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_row!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:row row_count:4&gt;</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">to_h</span> <span class="ruby-comment"># =&gt; {&quot;Name&quot;=&gt;&quot;foo&quot;, &quot;Value&quot;=&gt;3}</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_h</span> <span class="ruby-comment"># =&gt; {&quot;Name&quot;=&gt;&quot;bar&quot;, &quot;Value&quot;=&gt;4}</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">2</span>].<span class="ruby-identifier">to_h</span> <span class="ruby-comment"># =&gt; {&quot;Name&quot;=&gt;&quot;baz&quot;, &quot;Value&quot;=&gt;5}</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col row_count:4&gt;</span>
</pre>

<p>If there are too few values, fills with <code>nil</code> values:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Value&#39;</span>] = [<span class="ruby-value">0</span>]
<span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Value&#39;</span>] <span class="ruby-comment"># =&gt; [0, nil, nil]</span>
</pre>

<p>If there are too many values, ignores the extra values:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Value&#39;</span>] = [<span class="ruby-value">0</span>, <span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>, <span class="ruby-value">4</span>]
<span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Value&#39;</span>] <span class="ruby-comment"># =&gt; [0, 1, 2]</span>
</pre>

<p>If the column does not exist, extends the table by adding columns:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Note&#39;</span>] = [<span class="ruby-string">&#39;x&#39;</span>, <span class="ruby-string">&#39;y&#39;</span>, <span class="ruby-string">&#39;z&#39;</span>]
<span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Note&#39;</span>] <span class="ruby-comment"># =&gt; [&quot;x&quot;, &quot;y&quot;, &quot;z&quot;]</span>
<span class="ruby-comment"># The rows, as revised:</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_row!</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">to_h</span> <span class="ruby-comment"># =&gt; {&quot;Name&quot;=&gt;&quot;foo&quot;, &quot;Value&quot;=&gt;0, &quot;Note&quot;=&gt;&quot;x&quot;}</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_h</span> <span class="ruby-comment"># =&gt; {&quot;Name&quot;=&gt;&quot;bar&quot;, &quot;Value&quot;=&gt;1, &quot;Note&quot;=&gt;&quot;y&quot;}</span>
<span class="ruby-identifier">table</span>[<span class="ruby-value">2</span>].<span class="ruby-identifier">to_h</span> <span class="ruby-comment"># =&gt; {&quot;Name&quot;=&gt;&quot;baz&quot;, &quot;Value&quot;=&gt;2, &quot;Note&quot;=&gt;&quot;z&quot;}</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col!</span>
</pre>

<p>If a single value is given, replaces all fields in the column with that value:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Value&#39;</span>] = <span class="ruby-string">&#39;bat&#39;</span>
<span class="ruby-identifier">table</span>[<span class="ruby-string">&#39;Value&#39;</span>] <span class="ruby-comment"># =&gt; [&quot;bat&quot;, &quot;bat&quot;, &quot;bat&quot;]</span>
</pre>

                              <div class="method-source-code" id="5B-5D-3D-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 649</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">[]=</span>(<span class="ruby-identifier">index_or_header</span>, <span class="ruby-identifier">value</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@mode</span> <span class="ruby-operator">==</span> <span class="ruby-value">:row</span> <span class="ruby-keyword">or</span>  <span class="ruby-comment"># by index</span>
     (<span class="ruby-ivar">@mode</span> <span class="ruby-operator">==</span> <span class="ruby-value">:col_or_row</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">index_or_header</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Integer</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Array</span>
      <span class="ruby-ivar">@table</span>[<span class="ruby-identifier">index_or_header</span>] = <span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">headers</span>, <span class="ruby-identifier">value</span>)
    <span class="ruby-keyword">else</span>
      <span class="ruby-ivar">@table</span>[<span class="ruby-identifier">index_or_header</span>] = <span class="ruby-identifier">value</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>                 <span class="ruby-comment"># set column</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-identifier">index_or_header</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Integer</span>
      <span class="ruby-identifier">index</span> = <span class="ruby-ivar">@headers</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">index_or_header</span>) <span class="ruby-operator">||</span> <span class="ruby-ivar">@headers</span>.<span class="ruby-identifier">size</span>
      <span class="ruby-ivar">@headers</span>[<span class="ruby-identifier">index</span>] = <span class="ruby-identifier">index_or_header</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Array</span>  <span class="ruby-comment"># multiple values</span>
      <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">header_row?</span>
          <span class="ruby-identifier">row</span>[<span class="ruby-identifier">index_or_header</span>] = <span class="ruby-identifier">index_or_header</span>
        <span class="ruby-keyword">else</span>
          <span class="ruby-identifier">row</span>[<span class="ruby-identifier">index_or_header</span>] = <span class="ruby-identifier">value</span>[<span class="ruby-identifier">i</span>]
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">else</span>                  <span class="ruby-comment"># repeated value</span>
      <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">header_row?</span>
          <span class="ruby-identifier">row</span>[<span class="ruby-identifier">index_or_header</span>] = <span class="ruby-identifier">index_or_header</span>
        <span class="ruby-keyword">else</span>
          <span class="ruby-identifier">row</span>[<span class="ruby-identifier">index_or_header</span>] = <span class="ruby-identifier">value</span>
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-by_col" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          by_col &rarr; table_dup
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a duplicate of <code>self</code>, in column mode (see <a href="#class-CSV::Table-label-Column+Mode">Column Mode</a>):</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">mode</span> <span class="ruby-comment"># =&gt; :col_or_row</span>
<span class="ruby-identifier">dup_table</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col</span>
<span class="ruby-identifier">dup_table</span>.<span class="ruby-identifier">mode</span> <span class="ruby-comment"># =&gt; :col</span>
<span class="ruby-identifier">dup_table</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">table</span>) <span class="ruby-comment"># =&gt; false # It&#39;s a dup</span>
</pre>

<p>This may be used to chain method calls without changing the mode (but also will affect performance and memory usage):</p>

<pre class="ruby"><span class="ruby-identifier">dup_table</span>.<span class="ruby-identifier">by_col</span>[<span class="ruby-string">&#39;Name&#39;</span>]
</pre>

<p>Also note that changes to the duplicate table will not affect the original.</p>

                              <div class="method-source-code" id="by_col-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 242</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">by_col</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@table</span>.<span class="ruby-identifier">dup</span>).<span class="ruby-identifier">by_col!</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-by_col-21" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          by_col! &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the mode for <code>self</code> to column mode (see <a href="#class-CSV::Table-label-Column+Mode">Column Mode</a>); returns <code>self</code>:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">mode</span> <span class="ruby-comment"># =&gt; :col_or_row</span>
<span class="ruby-identifier">table1</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col!</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">mode</span> <span class="ruby-comment"># =&gt; :col</span>
<span class="ruby-identifier">table1</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">table</span>) <span class="ruby-comment"># =&gt; true # Returned self</span>
</pre>

                              <div class="method-source-code" id="by_col-21-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 257</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">by_col!</span>
  <span class="ruby-ivar">@mode</span> = <span class="ruby-value">:col</span>

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-by_col_or_row" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          by_col_or_row &rarr; table_dup
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a duplicate of <code>self</code>, in mixed mode (see <a href="#class-CSV::Table-label-Mixed+Mode">Mixed Mode</a>):</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>).<span class="ruby-identifier">by_col!</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">mode</span> <span class="ruby-comment"># =&gt; :col</span>
<span class="ruby-identifier">dup_table</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col_or_row</span>
<span class="ruby-identifier">dup_table</span>.<span class="ruby-identifier">mode</span> <span class="ruby-comment"># =&gt; :col_or_row</span>
<span class="ruby-identifier">dup_table</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">table</span>) <span class="ruby-comment"># =&gt; false # It&#39;s a dup</span>
</pre>

<p>This may be used to chain method calls without changing the mode (but also will affect performance and memory usage):</p>

<pre class="ruby"><span class="ruby-identifier">dup_table</span>.<span class="ruby-identifier">by_col_or_row</span>[<span class="ruby-string">&#39;Name&#39;</span>]
</pre>

<p>Also note that changes to the duplicate table will not affect the original.</p>

                              <div class="method-source-code" id="by_col_or_row-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 280</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">by_col_or_row</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@table</span>.<span class="ruby-identifier">dup</span>).<span class="ruby-identifier">by_col_or_row!</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-by_col_or_row-21" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          by_col_or_row! &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the mode for <code>self</code> to mixed mode (see <a href="#class-CSV::Table-label-Mixed+Mode">Mixed Mode</a>); returns <code>self</code>:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>).<span class="ruby-identifier">by_col!</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">mode</span> <span class="ruby-comment"># =&gt; :col</span>
<span class="ruby-identifier">table1</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col_or_row!</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">mode</span> <span class="ruby-comment"># =&gt; :col_or_row</span>
<span class="ruby-identifier">table1</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">table</span>) <span class="ruby-comment"># =&gt; true # Returned self</span>
</pre>

                              <div class="method-source-code" id="by_col_or_row-21-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 295</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">by_col_or_row!</span>
  <span class="ruby-ivar">@mode</span> = <span class="ruby-value">:col_or_row</span>

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-by_row" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          by_row &rarr; table_dup
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a duplicate of <code>self</code>, in row mode (see <a href="#class-CSV::Table-label-Row+Mode">Row Mode</a>):</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">mode</span> <span class="ruby-comment"># =&gt; :col_or_row</span>
<span class="ruby-identifier">dup_table</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_row</span>
<span class="ruby-identifier">dup_table</span>.<span class="ruby-identifier">mode</span> <span class="ruby-comment"># =&gt; :row</span>
<span class="ruby-identifier">dup_table</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">table</span>) <span class="ruby-comment"># =&gt; false # It&#39;s a dup</span>
</pre>

<p>This may be used to chain method calls without changing the mode (but also will affect performance and memory usage):</p>

<pre class="ruby"><span class="ruby-identifier">dup_table</span>.<span class="ruby-identifier">by_row</span>[<span class="ruby-value">1</span>]
</pre>

<p>Also note that changes to the duplicate table will not affect the original.</p>

                              <div class="method-source-code" id="by_row-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 318</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">by_row</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@table</span>.<span class="ruby-identifier">dup</span>).<span class="ruby-identifier">by_row!</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-by_row-21" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          by_row! &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the mode for <code>self</code> to row mode (see <a href="#class-CSV::Table-label-Row+Mode">Row Mode</a>); returns <code>self</code>:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">mode</span> <span class="ruby-comment"># =&gt; :col_or_row</span>
<span class="ruby-identifier">table1</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_row!</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">mode</span> <span class="ruby-comment"># =&gt; :row</span>
<span class="ruby-identifier">table1</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">table</span>) <span class="ruby-comment"># =&gt; true # Returned self</span>
</pre>

                              <div class="method-source-code" id="by_row-21-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 333</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">by_row!</span>
  <span class="ruby-ivar">@mode</span> = <span class="ruby-value">:row</span>

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-delete" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          delete(*indexes) &rarr; deleted_values
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          delete(*headers) &rarr; deleted_values
                              </span>
                            </div>

                            <div class="method-description">
                              <p>If the access mode is <code>:row</code> or <code>:col_or_row</code>, and each argument is either an Integer or a Range, returns deleted rows. Otherwise, returns deleted columns data.</p>

<p>In either case, the returned values are in the order specified by the arguments.  Arguments may be repeated.</p>
<hr>

<p>Returns rows as an Array of CSV::Row objects.</p>

<p>One index:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">deleted_values</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">deleted_values</span> <span class="ruby-comment"># =&gt; [#&lt;CSV::Row &quot;Name&quot;:&quot;foo&quot; &quot;Value&quot;:&quot;0&quot;&gt;]</span>
</pre>

<p>Two indexes:</p>

<pre class="ruby"><span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">deleted_values</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">2</span>, <span class="ruby-value">0</span>)
<span class="ruby-identifier">deleted_values</span> <span class="ruby-comment"># =&gt; [#&lt;CSV::Row &quot;Name&quot;:&quot;baz&quot; &quot;Value&quot;:&quot;2&quot;&gt;, #&lt;CSV::Row &quot;Name&quot;:&quot;foo&quot; &quot;Value&quot;:&quot;0&quot;&gt;]</span>
</pre>
<hr>

<p>Returns columns data as column Arrays.</p>

<p>One header:</p>

<pre class="ruby"><span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">deleted_values</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-string">&#39;Name&#39;</span>)
<span class="ruby-identifier">deleted_values</span> <span class="ruby-comment"># =&gt; [&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;]</span>
</pre>

<p>Two headers:</p>

<pre class="ruby"><span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">deleted_values</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-string">&#39;Value&#39;</span>, <span class="ruby-string">&#39;Name&#39;</span>)
<span class="ruby-identifier">deleted_values</span> <span class="ruby-comment"># =&gt; [[&quot;0&quot;, &quot;1&quot;, &quot;2&quot;], [&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;]]</span>
</pre>

                              <div class="method-source-code" id="delete-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 834</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">delete</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">indexes_or_headers</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">indexes_or_headers</span>.<span class="ruby-identifier">empty?</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;wrong number of arguments (given 0, expected 1+)&quot;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">deleted_values</span> = <span class="ruby-identifier">indexes_or_headers</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">index_or_header</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@mode</span> <span class="ruby-operator">==</span> <span class="ruby-value">:row</span> <span class="ruby-keyword">or</span>  <span class="ruby-comment"># by index</span>
        (<span class="ruby-ivar">@mode</span> <span class="ruby-operator">==</span> <span class="ruby-value">:col_or_row</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">index_or_header</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Integer</span>)
      <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">delete_at</span>(<span class="ruby-identifier">index_or_header</span>)
    <span class="ruby-keyword">else</span>                 <span class="ruby-comment"># by header</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">index_or_header</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Integer</span>
        <span class="ruby-ivar">@headers</span>.<span class="ruby-identifier">delete_at</span>(<span class="ruby-identifier">index_or_header</span>)
      <span class="ruby-keyword">else</span>
        <span class="ruby-ivar">@headers</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">index_or_header</span>)
      <span class="ruby-keyword">end</span>
      <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">index_or_header</span>).<span class="ruby-identifier">last</span> }
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">indexes_or_headers</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
    <span class="ruby-identifier">deleted_values</span>[<span class="ruby-value">0</span>]
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">deleted_values</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-delete_if" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          delete_if {|row_or_column| ... } &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Removes rows or columns for which the block returns a truthy value; returns <code>self</code>.</p>

<p>Removes rows when the access mode is <code>:row</code> or <code>:col_or_row</code>; calls the block with each CSV::Row object:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_row!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:row row_count:4&gt;</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment"># =&gt; 3</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">delete_if</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span> <span class="ruby-identifier">row</span>[<span class="ruby-string">&#39;Name&#39;</span>].<span class="ruby-identifier">start_with?</span>(<span class="ruby-string">&#39;b&#39;</span>) }
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment"># =&gt; 1</span>
</pre>

<p>Removes columns when the access mode is <code>:col</code>; calls the block with each column as a 2-element array containing the header and an Array of column fields:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col row_count:4&gt;</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">headers</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment"># =&gt; 2</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">delete_if</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">column_data</span><span class="ruby-operator">|</span> <span class="ruby-identifier">column_data</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-string">&#39;2&#39;</span>) }
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">headers</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment"># =&gt; 1</span>
</pre>

<p>Returns a new Enumerator if no block is given:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">delete_if</span> <span class="ruby-comment"># =&gt; #&lt;Enumerator: #&lt;CSV::Table mode:col_or_row row_count:4&gt;:delete_if&gt;</span>
</pre>

                              <div class="method-source-code" id="delete_if-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 887</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">delete_if</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">enum_for</span>(<span class="ruby-identifier">__method__</span>) { <span class="ruby-ivar">@mode</span> <span class="ruby-operator">==</span> <span class="ruby-value">:row</span> <span class="ruby-keyword">or</span> <span class="ruby-ivar">@mode</span> <span class="ruby-operator">==</span> <span class="ruby-value">:col_or_row</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">size</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">headers</span>.<span class="ruby-identifier">size</span> } <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>

  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@mode</span> <span class="ruby-operator">==</span> <span class="ruby-value">:row</span> <span class="ruby-keyword">or</span> <span class="ruby-ivar">@mode</span> <span class="ruby-operator">==</span> <span class="ruby-value">:col_or_row</span>  <span class="ruby-comment"># by index</span>
    <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">delete_if</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">else</span>                                      <span class="ruby-comment"># by header</span>
    <span class="ruby-identifier">headers</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">header</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">delete</span>(<span class="ruby-identifier">header</span>) <span class="ruby-keyword">if</span> <span class="ruby-keyword">yield</span>([<span class="ruby-identifier">header</span>, <span class="ruby-keyword">self</span>[<span class="ruby-identifier">header</span>]])
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">self</span> <span class="ruby-comment"># for chaining</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-dig" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">dig</span><span
                                class="method-args">(index_or_header, *index_or_headers)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Extracts the nested value specified by the sequence of <code>index</code> or <code>header</code> objects by calling dig at each step, returning nil if any intermediate step is nil.</p>

                              <div class="method-source-code" id="dig-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 1021</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">dig</span>(<span class="ruby-identifier">index_or_header</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">index_or_headers</span>)
  <span class="ruby-identifier">value</span> = <span class="ruby-keyword">self</span>[<span class="ruby-identifier">index_or_header</span>]
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span>
    <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">index_or_headers</span>.<span class="ruby-identifier">empty?</span>
    <span class="ruby-identifier">value</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:dig</span>)
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">&quot;#{value.class} does not have \#dig method&quot;</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">value</span>.<span class="ruby-identifier">dig</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">index_or_headers</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          each {|row_or_column| ... ) &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Calls the block with each row or column; returns <code>self</code>.</p>

<p>When the access mode is <code>:row</code> or <code>:col_or_row</code>, calls the block with each CSV::Row object:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_row!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:row row_count:4&gt;</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">row</span> }
</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-comment">#&lt;CSV::Row &quot;Name&quot;:&quot;foo&quot; &quot;Value&quot;:&quot;0&quot;&gt;</span>
<span class="ruby-comment">#&lt;CSV::Row &quot;Name&quot;:&quot;bar&quot; &quot;Value&quot;:&quot;1&quot;&gt;</span>
<span class="ruby-comment">#&lt;CSV::Row &quot;Name&quot;:&quot;baz&quot; &quot;Value&quot;:&quot;2&quot;&gt;</span>
</pre>

<p>When the access mode is <code>:col</code>, calls the block with each column as a 2-element array containing the header and an Array of column fields:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>.<span class="ruby-identifier">by_col!</span> <span class="ruby-comment"># =&gt; #&lt;CSV::Table mode:col row_count:4&gt;</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">column_data</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">column_data</span> }
</pre>

<p>Output:</p>

<pre class="ruby">[<span class="ruby-string">&quot;Name&quot;</span>, [<span class="ruby-string">&quot;foo&quot;</span>, <span class="ruby-string">&quot;bar&quot;</span>, <span class="ruby-string">&quot;baz&quot;</span>]]
[<span class="ruby-string">&quot;Value&quot;</span>, [<span class="ruby-string">&quot;0&quot;</span>, <span class="ruby-string">&quot;1&quot;</span>, <span class="ruby-string">&quot;2&quot;</span>]]
</pre>

<p>Returns a new Enumerator if no block is given:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>.<span class="ruby-identifier">each</span> <span class="ruby-comment"># =&gt; #&lt;Enumerator: #&lt;CSV::Table mode:col row_count:4&gt;:each&gt;</span>
</pre>

                              <div class="method-source-code" id="each-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 930</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">enum_for</span>(<span class="ruby-identifier">__method__</span>) { <span class="ruby-ivar">@mode</span> <span class="ruby-operator">==</span> <span class="ruby-value">:col</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">headers</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">size</span> } <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>

  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@mode</span> <span class="ruby-operator">==</span> <span class="ruby-value">:col</span>
    <span class="ruby-identifier">headers</span>.<span class="ruby-identifier">each</span>.<span class="ruby-identifier">with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">header</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">yield</span>([<span class="ruby-identifier">header</span>, <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span> <span class="ruby-identifier">row</span>[<span class="ruby-identifier">header</span>, <span class="ruby-identifier">i</span>]}])
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">each</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">self</span> <span class="ruby-comment"># for chaining</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-headers" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          headers &rarr; array_of_headers
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new Array containing the String headers for the table.</p>

<p>If the table is not empty, returns the headers from the first row:</p>

<pre class="ruby"><span class="ruby-identifier">rows</span> = [
  <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&#39;Foo&#39;</span>, <span class="ruby-string">&#39;Bar&#39;</span>], []),
  <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&#39;FOO&#39;</span>, <span class="ruby-string">&#39;BAR&#39;</span>], []),
  <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&#39;foo&#39;</span>, <span class="ruby-string">&#39;bar&#39;</span>], []),
]
<span class="ruby-identifier">table</span>  = <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Table</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">rows</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">headers</span> <span class="ruby-comment"># =&gt; [&quot;Foo&quot;, &quot;Bar&quot;]</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">headers</span> <span class="ruby-comment"># =&gt; [&quot;FOO&quot;, &quot;BAR&quot;]</span>
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">headers</span> <span class="ruby-comment"># =&gt; [&quot;foo&quot;, &quot;bar&quot;]</span>
</pre>

<p>If the table is empty, returns a copy of the headers in the table itself:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">headers</span> <span class="ruby-comment"># =&gt; [&quot;Foo&quot;, &quot;Bar&quot;]</span>
</pre>

                              <div class="method-source-code" id="headers-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 360</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">headers</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">empty?</span>
    <span class="ruby-ivar">@headers</span>.<span class="ruby-identifier">dup</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">headers</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          inspect &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a <code>US-ASCII</code>-encoded String showing table:</p>
<ul><li>
<p>Class: <code>CSV::Table</code>.</p>
</li><li>
<p>Access mode: <code>:row</code>, <code>:col</code>, or <code>:col_or_row</code>.</p>
</li><li>
<p>Size:  <a href="Row.html"><code>Row</code></a> count, including the header row.</p>
</li></ul>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">inspect</span> <span class="ruby-comment"># =&gt; &quot;#&lt;CSV::Table mode:col_or_row row_count:4&gt;\nName,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
</pre>

                              <div class="method-source-code" id="inspect-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 1048</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">inspect</span>
  <span class="ruby-identifier">inspected</span> = <span class="ruby-node">+&quot;#&lt;#{self.class} mode:#{@mode} row_count:#{to_a.size}&gt;&quot;</span>
  <span class="ruby-identifier">summary</span> = <span class="ruby-identifier">to_csv</span>(<span class="ruby-value">limit:</span> <span class="ruby-value">5</span>)
  <span class="ruby-identifier">inspected</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">summary</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">summary</span>.<span class="ruby-identifier">encoding</span>.<span class="ruby-identifier">ascii_compatible?</span>
  <span class="ruby-identifier">inspected</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-push" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          push(*rows_or_arrays) &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>A shortcut for appending multiple rows. Equivalent to:</p>

<pre class="ruby"><span class="ruby-identifier">rows</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span> <span class="ruby-keyword">self</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">row</span> }
</pre>

<p>Each argument may be either a CSV::Row object or an Array:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">rows</span> = [
  <span class="ruby-constant">CSV</span><span class="ruby-operator">::</span><span class="ruby-constant">Row</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">table</span>.<span class="ruby-identifier">headers</span>, [<span class="ruby-string">&#39;bat&#39;</span>, <span class="ruby-value">3</span>]),
  [<span class="ruby-string">&#39;bam&#39;</span>, <span class="ruby-value">4</span>]
]
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">push</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">rows</span>)
<span class="ruby-identifier">table</span>[<span class="ruby-value">3</span><span class="ruby-operator">..</span><span class="ruby-value">4</span>] <span class="ruby-comment"># =&gt; [#&lt;CSV::Row &quot;Name&quot;:&quot;bat&quot; &quot;Value&quot;:3&gt;, #&lt;CSV::Row &quot;Name&quot;:&quot;bam&quot; &quot;Value&quot;:4&gt;]</span>
</pre>

                              <div class="method-source-code" id="push-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 788</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">push</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">rows</span>)
  <span class="ruby-identifier">rows</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span> <span class="ruby-keyword">self</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">row</span> }

  <span class="ruby-keyword">self</span> <span class="ruby-comment"># for chaining</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_a" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_a &rarr; array_of_arrays
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the table as an Array of Arrays; the headers are in the first row:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">to_a</span> <span class="ruby-comment"># =&gt; [[&quot;Name&quot;, &quot;Value&quot;], [&quot;foo&quot;, &quot;0&quot;], [&quot;bar&quot;, &quot;1&quot;], [&quot;baz&quot;, &quot;2&quot;]]</span>
</pre>

                              <div class="method-source-code" id="to_a-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 978</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_a</span>
  <span class="ruby-identifier">array</span> = [<span class="ruby-identifier">headers</span>]
  <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">array</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">row</span>.<span class="ruby-identifier">fields</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">header_row?</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">array</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_csv" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_csv(**options) &rarr; csv_string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the table as CSV string. See <a href="../CSV.html#class-CSV-label-Options+for+Generating">Options for Generating</a>.</p>

<p>Defaults option <code>write_headers</code> to <code>true</code>:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">to_csv</span> <span class="ruby-comment"># =&gt; &quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
</pre>

<p>Omits the headers if option <code>write_headers</code> is given as <code>false</code> (see {Option <code>write_headers</code><a href="../CSV.html#class-CSV-label-Option+write_headers">}</a>):</p>

<pre class="ruby"><span class="ruby-identifier">table</span>.<span class="ruby-identifier">to_csv</span>(<span class="ruby-value">write_headers:</span> <span class="ruby-keyword">false</span>) <span class="ruby-comment"># =&gt; &quot;foo,0\nbar,1\nbaz,2\n&quot;</span>
</pre>

<p>Limit rows if option <code>limit</code> is given like <code>2</code>:</p>

<pre class="ruby"><span class="ruby-identifier">table</span>.<span class="ruby-identifier">to_csv</span>(<span class="ruby-value">limit:</span> <span class="ruby-value">2</span>) <span class="ruby-comment"># =&gt; &quot;Name,Value\nfoo,0\nbar,1\n&quot;</span>
</pre>

                              <div class="method-source-code" id="to_csv-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 1004</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_csv</span>(<span class="ruby-value">write_headers:</span> <span class="ruby-keyword">true</span>, <span class="ruby-value">limit:</span> <span class="ruby-keyword">nil</span>, <span class="ruby-operator">**</span><span class="ruby-identifier">options</span>)
  <span class="ruby-identifier">array</span> = <span class="ruby-identifier">write_headers</span> <span class="ruby-operator">?</span> [<span class="ruby-identifier">headers</span>.<span class="ruby-identifier">to_csv</span>(<span class="ruby-operator">**</span><span class="ruby-identifier">options</span>)] <span class="ruby-operator">:</span> []
  <span class="ruby-identifier">limit</span> <span class="ruby-operator">||=</span> <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">size</span>
  <span class="ruby-identifier">limit</span> = <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">limit</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">limit</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
  <span class="ruby-identifier">limit</span> = <span class="ruby-value">0</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">limit</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
  <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">first</span>(<span class="ruby-identifier">limit</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">array</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">row</span>.<span class="ruby-identifier">fields</span>.<span class="ruby-identifier">to_csv</span>(<span class="ruby-operator">**</span><span class="ruby-identifier">options</span>)) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">header_row?</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">array</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">&quot;&quot;</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Table.html#method-i-to_s">to_s</a>
                            </div>

                          </div>

                  <div id="method-i-to_s" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">to_s</span><span
                                class="method-args">(write_headers: true, limit: nil, **options)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Table.html#method-i-to_csv">to_csv</a>
                            </div>
                          </div>

                  <div id="method-i-values_at" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          values_at(*indexes) &rarr; array_of_rows
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          values_at(*headers) &rarr; array_of_columns_data
                              </span>
                            </div>

                            <div class="method-description">
                              <p>If the access mode is <code>:row</code> or <code>:col_or_row</code>, and each argument is either an Integer or a Range, returns rows. Otherwise, returns columns data.</p>

<p>In either case, the returned values are in the order specified by the arguments.  Arguments may be repeated.</p>
<hr>

<p>Returns rows as an Array of CSV::Row objects.</p>

<p>No argument:</p>

<pre class="ruby"><span class="ruby-identifier">source</span> = <span class="ruby-string">&quot;Name,Value\nfoo,0\nbar,1\nbaz,2\n&quot;</span>
<span class="ruby-identifier">table</span> = <span class="ruby-constant">CSV</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">headers:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">table</span>.<span class="ruby-identifier">values_at</span> <span class="ruby-comment"># =&gt; []</span>
</pre>

<p>One index:</p>

<pre class="ruby"><span class="ruby-identifier">values</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">values</span> <span class="ruby-comment"># =&gt; [#&lt;CSV::Row &quot;Name&quot;:&quot;foo&quot; &quot;Value&quot;:&quot;0&quot;&gt;]</span>
</pre>

<p>Two indexes:</p>

<pre class="ruby"><span class="ruby-identifier">values</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-value">2</span>, <span class="ruby-value">0</span>)
<span class="ruby-identifier">values</span> <span class="ruby-comment"># =&gt; [#&lt;CSV::Row &quot;Name&quot;:&quot;baz&quot; &quot;Value&quot;:&quot;2&quot;&gt;, #&lt;CSV::Row &quot;Name&quot;:&quot;foo&quot; &quot;Value&quot;:&quot;0&quot;&gt;]</span>
</pre>

<p>One Range:</p>

<pre class="ruby"><span class="ruby-identifier">values</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">2</span>)
<span class="ruby-identifier">values</span> <span class="ruby-comment"># =&gt; [#&lt;CSV::Row &quot;Name&quot;:&quot;bar&quot; &quot;Value&quot;:&quot;1&quot;&gt;, #&lt;CSV::Row &quot;Name&quot;:&quot;baz&quot; &quot;Value&quot;:&quot;2&quot;&gt;]</span>
</pre>

<p>Ranges and indexes:</p>

<pre class="ruby"><span class="ruby-identifier">values</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">1</span>, <span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">2</span>, <span class="ruby-value">0</span>, <span class="ruby-value">2</span>)
<span class="ruby-identifier">pp</span> <span class="ruby-identifier">values</span>
</pre>

<p>Output:</p>

<pre>[#&lt;CSV::Row &quot;Name&quot;:&quot;foo&quot; &quot;Value&quot;:&quot;0&quot;&gt;,
 #&lt;CSV::Row &quot;Name&quot;:&quot;bar&quot; &quot;Value&quot;:&quot;1&quot;&gt;,
 #&lt;CSV::Row &quot;Name&quot;:&quot;bar&quot; &quot;Value&quot;:&quot;1&quot;&gt;,
 #&lt;CSV::Row &quot;Name&quot;:&quot;baz&quot; &quot;Value&quot;:&quot;2&quot;&gt;,
 #&lt;CSV::Row &quot;Name&quot;:&quot;foo&quot; &quot;Value&quot;:&quot;0&quot;&gt;,
 #&lt;CSV::Row &quot;Name&quot;:&quot;baz&quot; &quot;Value&quot;:&quot;2&quot;&gt;]</pre>
<hr>

<p>Returns columns data as row Arrays, each consisting of the specified columns data for that row:</p>

<pre class="ruby"><span class="ruby-identifier">values</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-string">&#39;Name&#39;</span>)
<span class="ruby-identifier">values</span> <span class="ruby-comment"># =&gt; [[&quot;foo&quot;], [&quot;bar&quot;], [&quot;baz&quot;]]</span>
<span class="ruby-identifier">values</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-string">&#39;Value&#39;</span>, <span class="ruby-string">&#39;Name&#39;</span>)
<span class="ruby-identifier">values</span> <span class="ruby-comment"># =&gt; [[&quot;0&quot;, &quot;foo&quot;], [&quot;1&quot;, &quot;bar&quot;], [&quot;2&quot;, &quot;baz&quot;]]</span>
</pre>

                              <div class="method-source-code" id="values_at-source">
            <pre><span class="ruby-comment"># File csv/table.rb, line 734</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">values_at</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">indices_or_headers</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@mode</span> <span class="ruby-operator">==</span> <span class="ruby-value">:row</span> <span class="ruby-keyword">or</span>  <span class="ruby-comment"># by indices</span>
     ( <span class="ruby-ivar">@mode</span> <span class="ruby-operator">==</span> <span class="ruby-value">:col_or_row</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">indices_or_headers</span>.<span class="ruby-identifier">all?</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
                                  <span class="ruby-identifier">index</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Integer</span>)         <span class="ruby-keyword">or</span>
                                  ( <span class="ruby-identifier">index</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Range</span>)         <span class="ruby-keyword">and</span>
                                    <span class="ruby-identifier">index</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Integer</span>) <span class="ruby-keyword">and</span>
                                    <span class="ruby-identifier">index</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Integer</span>) )
                                <span class="ruby-keyword">end</span> )
    <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">indices_or_headers</span>)
  <span class="ruby-keyword">else</span>                 <span class="ruby-comment"># by headers</span>
    <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">indices_or_headers</span>) }
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

